package com.li.configserve.utils.redis;

import org.redisson.api.RedissonClient;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author LiDong
 * @version 1.0.0
 * @createTime 2021/11/28 15:52
 */
@Component
public class RedissonUtils {

    private static RedissonClient redissonClient;

    /**
     * 初始化静态变量
     *
     * @param redissonClient
     */
    public RedissonUtils(RedissonClient redissonClient) {
        RedissonUtils.redissonClient = redissonClient;
    }

    /**
     * 从 Redis 中获取集合
     *
     * @param redisKey
     * @return
     */
    public static List<?> getMenuFromRedis(String redisKey) {
        return redissonClient.getList(redisKey).readAll();
    }

    /**
     * Redis 中添加集合
     *
     * @param redisKey
     * @param list
     */
    public static void addList(String redisKey, List<?> list) {
        // 删除
        redissonClient.getList(redisKey).delete();
        // 添加
        redissonClient.getList(redisKey).addAll(list);
    }
}
